//引入jsonwebtoken模块
let jwt = require("jsonwebtoken");
const tokenKey = 'azrael'
const TOKEN_EXPIRE_SENCOND = 60 * 60 * 24;
const Token= {
    //加密
    encrypt: function(data){
        return jwt.sign(data,tokenKey,{expiresIn:TOKEN_EXPIRE_SENCOND})
    },
    //解密
    decrypt: function(token){
        try {
            let data = jwt.verify(token,tokenKey);
            return {
                token:true,
                data:data,
            }
        } catch (e){
            return {
                token:false,
                data:e
            }
        }
    }
}
module.exports = Token;
